<?php

namespace App\Model\Spread;

use Hyperf\DbConnection\Model\Model;

class SpreadAccount extends Model
{
    protected $connection = 'spread';
    protected $table = 'spread_account';

    /**
     * @param $id
     * @return bool
     */
    public static function getInfoByUserId($id)
    {
        $data = self::where('id',$id)->first();

        if (empty($data)) {
            return false;
        }
        log_info(__CLASS__.':data:'.json_encode($data->toArray()));
        $info = $data->toArray();
        log_info(__CLASS__.':return:'.(bool)$info['status']);
        return (bool)$info['status'];
    }

    /**
     * @param $data
     * @return bool
     */
    public static function checkUserId($data)
    {
        $id = $data;
        //        $id = openssl_decrypt(urldecode($data), 'AES-128-ECB', 'spread') ?? "";
//        log_info(__CLASS__.':data:'.$data.':id:'.$id);
        return $id;
    }

    /**
     * @param $id
     * @return \Hyperf\Database\Model\Builder|\Hyperf\Database\Model\Model|object|null
     */
    public function getInfoById($id)
    {
        return self::where('id',$id)->first();
    }
}